package
{
	import flash.display.*;
	import flash.display.Sprite;
	import flash.events.*;
	import flash.net.URLRequest;
	import flash.text.TextField;
	import flash.ui.Keyboard;
	
	[SWF( backgroundColor="0x000000")]
	public class VegaGame extends Sprite
	{
		
		private var urlResult:TextField = new TextField;
		private var imgResult:TextField = new TextField;		
		private var stageInfo:TextField = new TextField;	
		
		private var enterprise:Bitmap;	
		private var defiant:Bitmap;	
		
		public function VegaGame()
		{
			// Set Default APPLICATION values
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.quality = StageQuality.MEDIUM;
			stage.frameRate = 50;
			stage.stageWidth =600;
			stage.stageHeight = 300;

			// Full screen
			addEventListener(MouseEvent.CLICK, toggleFullScreen);

			
			// Draw a sprite
			this.graphics.beginFill(0x555555);
			this.graphics.drawCircle(100,100,25);
			this.graphics.endFill();
			
			// Create Edit Box
			addChild(urlResult); 	urlResult.border=true;	urlResult.borderColor=0xFFFFFF;
			urlResult.width = 200;	urlResult.height = 20; 
			urlResult.x = 50;	urlResult.y = 10;   urlResult.textColor = 0xFFFFFF;
			
//			addChild(imgResult); //imgResult.border=true;	urlResult.borderColor=0xFFFFFF;
//			imgResult.x = 50;	imgResult.y = 90;	imgResult.textColor = 0xFFFFFF;
			
			var ul:uLoader = new uLoader("http://vegawar.appspot.com/vegasite",urlResult);

			// load starship
			var l1:Loader = new Loader();
			l1.contentLoaderInfo.addEventListener(Event.COMPLETE,enterpriseComplete);
			l1.load(new URLRequest("http://cdn.vegawar.com/SmallEnterprise.png"));

			var l2:Loader = new Loader();
			l2.contentLoaderInfo.addEventListener(Event.COMPLETE,defiantComplete);
			l2.load(new URLRequest("http://cdn.vegawar.com/SmallDefiant.png"));			
			
			// Event trapping
			stage.addEventListener(KeyboardEvent.KEY_DOWN, keyEvent);
			
			
		}// VegaGame
		
		private function enterpriseComplete(event:Event):void{
			enterprise = (event.currentTarget.content);
			imgResult.text = "SmallEnterprise Loaded";
			this.addChild(enterprise);	enterprise.x=100;	enterprise.y=100;
		}

		private function defiantComplete(event:Event):void{
			defiant = (event.currentTarget.content);
			this.addChild(defiant);	defiant.x=200;	defiant.y=200;
		}		
		
		private function keyEvent(event:KeyboardEvent):void{
			
			trace("keyDownHandler: " + event.keyCode);
			
			if(event.keyCode==Keyboard.RIGHT){enterprise.rotationZ += 1;}
			if(event.keyCode==Keyboard.LEFT){enterprise.rotationZ -= 1;}
			if(event.keyCode==Keyboard.UP){enterprise.y -= 1;}
			if(event.keyCode==Keyboard.DOWN){enterprise.y += 1;}
			
		}
		
		private function toggleFullScreen(event:MouseEvent):void{
			
			//if normal size, go to fullscreen, else go to normal size
			
			if(stage.displayState=="normal"){
				stage.displayState="fullScreen";
			}else{
				stage.displayState="normal";
			}		
		}// toggleFullScreen
	}
}